/*
 *
 * This is a VoIP Application designed for local-network usage for voice and
 * messaging
 * Copyright (C) 2012  Imran M Yousuf (imyousuf@smitsol.com)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.smitsol.voip.api.impl;

import com.google.inject.AbstractModule;
import com.google.inject.TypeLiteral;
import com.smartitengineering.util.bean.PropertiesLocator;
import com.smitsol.voip.api.API;
import com.smitsol.voip.api.BindingService;
import com.smitsol.voip.api.BindingRegistryService;
import com.smitsol.voip.api.IdentityFactory;
import com.smitsol.voip.api.UserService;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;

/**
 *
 * @author imyousuf
 */
public class APIModule extends AbstractModule {

  @Override
  protected void configure() {
    bind(UserService.class).to(UserServiceImpl.class);
    bind(BindingService.class).to(BindingServiceImpl.class);
    bind(BindingRegistryService.class).to(BindingRegistryServiceImpl.class);
    bind(IdentityFactory.class).to(IdentityFactoryImpl.class);
    bind(API.class);
    PropertiesLocator propertiesLocator = new PropertiesLocator();
    propertiesLocator.setSmartLocations("com/smitsol/voip/api/config/config.properties");
    Properties props = new Properties();
    try {
      propertiesLocator.loadProperties(props);
    }
    catch (Exception ex) {
      throw new IllegalStateException(ex);
    }
    LinkedHashMap<String, String> configs = new LinkedHashMap<String, String>();
    configs.putAll((Map) props);
    bind(new TypeLiteral<Map<String, String>>() {
    }).toInstance(configs);
  }
}
